package com.xysl.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysDictData;
import com.ruoyi.system.api.domain.SysDictType;
import com.xysl.api.domain.XyslUser;
import com.xysl.api.model.XyslLoginUser;
import com.xysl.service.DictConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Tag(name = "系统字典配置接口", description = "系统字典配置接口")
@RestController
@RequestMapping("/dictConfig")
public class DictConfigController {

    @Resource
    private DictConfigService dictConfigService;

    @Operation(summary = "查询字典类型数据")
    @PostMapping("/queryDictTypeList")
    public R<List<SysDictType>> queryDictTypeList()
    {
        List<SysDictType> res = dictConfigService.queryDictTypeList();
        return R.ok(res);
    }


    @Operation(summary = "根据字典类型获取字典选项数据")
    @PostMapping("/queryDictDataByTypeList")
    public R<List<SysDictData>> queryDictDataByTypeList(
            @Parameter(description = "字典类型code")
            @RequestParam(required = false) String dictTypeCode)
    {
        XyslLoginUser xyslLoginUser = SecurityUtils.getXyslLoginUser();
        XyslUser xyslUser = xyslLoginUser.getXyslUser();
        List<SysDictData> res = dictConfigService.queryDictDataByTypeList(xyslUser,dictTypeCode);
        return R.ok(res);
    }
}
